import pandas as pd

def get_seq_list_from_log(filename):
    seq_list = []

    if 'client' in filename:
        with open(filename) as f:
            line = f.readline()
            while line:
                if 'OUTGOING' in line:
                    seq = int(line.split(',')[1].split('=')[1])
                    seq_list.append(seq)
                line = f.readline()
    # elif 'server' in filename:
    #     with open(filename) as f:
    #         line = f.readline()
    #         while line:
    #             if 'OUTGOING' in line:
    #                 seq = int(line.split(',')[1].split('=')[1])
    #                 seq_list.append(seq)
    #             line = f.readline()       

    ack_num = len(seq_list)
    max_seq = seq_list[-1]
    loss_rate = (max_seq - ack_num) / max_seq
    print('loss rate:', loss_rate)
    return seq_list


if __name__ == "__main__":
    # loss_set = get_seq_list_from_log('client-1687446069-1687446069')
    loss_set = get_seq_list_from_log('client-1687487799-1687487799')
    # loss_set = sorted(loss_set)
    # with open('satloss_tc50M150000_background.csv', 'w') as f:
    #     for seq in loss_set:
    #         f.write(str(seq) + '\n')
